package com.zj.fx.controller.info;

import com.zj.fx.common.base.BaseController;
import com.zj.fx.common.domain.AjaxResult;
import com.zj.fx.common.domain.ResultTable;
import com.zj.fx.model.auto.TsysRole;
import com.zj.fx.model.custom.Tablepar;
import com.github.pagehelper.PageInfo;
import com.zj.fx.model.info.InfoSubcompany;
import com.zj.fx.service.info.InfoSubcompanyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

/**
 * 分公司信息表Controller
 * @ClassName: InfoSubcompanyController
 * @author SQL
 * @date 2023-07-05 10:48:53
 */
@Api(value = "分公司信息表")
@Controller
@RequestMapping("/InfoSubcompanyController")
public class InfoSubcompanyController extends BaseController {

    private String prefix = "info/infoSubcompany";

    @Autowired
    private InfoSubcompanyService infoSubcompanyService;


    /**
     * 分公司信息表页面展示
     * @param model
     * @return String
     * @author SQL
     */
    @ApiOperation(value = "分页跳转", notes = "分页跳转")
    @GetMapping("/view")
    @RequiresPermissions("gen:infoSubcompany:view")
    public String view(ModelMap model) {
        return prefix + "/list";
    }

    /**
     * list集合
     * @param tablepar
     * @param
     * @return
     */
    //@Log(title = "分公司信息表", action = "111")
    @ApiOperation(value = "分页跳转", notes = "分页跳转")
    @GetMapping("/list")
    @RequiresPermissions("gen:infoSubcompany:list")
    @ResponseBody
    public ResultTable list(Tablepar tablepar, InfoSubcompany infoSubcompany) {
        PageInfo<InfoSubcompany> page = infoSubcompanyService.list(tablepar,infoSubcompany);
        return pageTable(page.getList(), page.getTotal());
    }

    /**
     * 新增跳转
     */
    @ApiOperation(value = "新增跳转", notes = "新增跳转")
    @GetMapping("/add")
    public String add(ModelMap modelMap) {
        return prefix + "/add";
    }

    /**
     * 新增保存
     * @param 
     * @return
     */
    //@Log(title = "分公司信息表新增", action = "111")
    @ApiOperation(value = "新增", notes = "新增")
    @PostMapping("/add")
    @RequiresPermissions("gen:infoSubcompany:add")
    @ResponseBody
    public AjaxResult add(@RequestBody InfoSubcompany infoSubcompany) {
        int b = infoSubcompanyService.insertSelective(infoSubcompany);
        if (b > 0) {
            return success();
        } else {
            return error();
        }
    }

    /**
     * 分公司信息表删除
     * @param ids
     * @return
     */
    //@Log(title = "分公司信息表删除", action = "111")
    @ApiOperation(value = "删除", notes = "删除")
    @DeleteMapping("/remove")
    @RequiresPermissions("gen:infoSubcompany:remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        int b = infoSubcompanyService.deleteByPrimaryKey(ids);
        if (b > 0) {
            return success();
        } else {
            return error();
        }
    }


    /**
     * 修改跳转
     * @param id
     * @param
     * @return
     */
    @ApiOperation(value = "修改跳转", notes = "修改跳转")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap map) {
        map.put("InfoSubcompany", infoSubcompanyService.selectByPrimaryKey(id));
        return prefix + "/edit";
    }

    /**
     * 修改保存
     */
    //@Log(title = "分公司信息表修改", action = "111")
    @ApiOperation(value = "修改保存", notes = "修改保存")
    @RequiresPermissions("gen:infoSubcompany:edit")
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(@RequestBody InfoSubcompany infoSubcompany) {
        return toAjax(infoSubcompanyService.updateByPrimaryKeySelective(infoSubcompany));
    }

    /**
     * 检查编号是否唯一
     *
     * @return
     */
    @ApiOperation(value = "检查Name唯一", notes = "检查Name唯一")
    @PostMapping("/checkNumUnique")
    @ResponseBody
    public int checkNumUnique(InfoSubcompany infoSubcompany) {
        int b = infoSubcompanyService.checkNumUnique(infoSubcompany);
        if (b > 0) {
            return 1;
        } else {
            return 0;
        }
    }


}
